<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件


function p($data){
   echo "<pre>";
   print_r($data);
   echo "</pre>";
}
/**
 * @param $code  200 表示成功
 * @param $msg
 * @param bool $isExit
 */
function returnAjax($code,$msg,$isExit=true){
    echo json_encode(['code'=>$code,'msg'=>$msg]);
    if($isExit) exit();
}

/**
 * 判断一个点是否在多边形内部
 * @param $polygon
 * @param $lnglat
 * @return bool
 */
function isPointInPolygon($polygon,$lnglat){
    $count = count($polygon);
    $px = $lnglat['lng'];
    $py = $lnglat['lat'];

    $flag = FALSE;

    for ($i = 0, $j = $count - 1; $i < $count; $j = $i, $i++) {
        $sy = $polygon[$i]['lng'];
        $sx = $polygon[$i]['lat'];
        $ty = $polygon[$j]['lng'];
        $tx = $polygon[$j]['lat'];

        if ($px == $sx && $py == $sy || $px == $tx && $py == $ty)
            return TRUE;

        if ($sy < $py && $ty >= $py || $sy >= $py && $ty < $py) {
            $x = $sx + ($py - $sy) * ($tx - $sx) / ($ty - $sy);
            if ($x == $px)
                return TRUE;
            if ($x > $px)
                $flag = !$flag;
        }
    }
    return $flag;
}

/**
 * 是否是字符串格式
 * @param $string
 * @return bool
 */
function is_json($string) {
 json_decode($string);
 return (json_last_error() == JSON_ERROR_NONE);
}